#include "Tile.h"
#include <iostream>
#include <cstdlib>
#include "../utils/base64.h"

Tile::Tile() : _binary("")
{
}

Tile::Tile(const char* data, const char* format, unsigned int transColor) :
	 _transColor(transColor)
{
	std::string f(format) ;
	if(f == "png")
		_format = PNG ;
	else if(f == "bmp")
		_format = BMP ;
	else if(f == "gif")
		_format = GIF ;
	else if(f == "jpg")
		_format = JPG ;
	else
	{
        std::cerr << "Unknown format" << std::endl ;
		exit(1) ;
	}

        _binary = base64_decode(std::string(data)) ;
}

bool Tile::empty() const 
{ 
    return _binary.length() == 0 ;
}

ImageFormat Tile::format() const 
{
	return _format ;
}

const char* Tile::binaryData() const 
{
    return _binary.c_str() ;
}

int Tile::binaryDataLength() const
{
    return _binary.length() ;
}

unsigned int Tile::transparentColor() const
{
    return _transColor ;
}

